home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / docs / mags / amique22.lha / ScreenMenu_v1.2.lha / ScreenMenu_v1.2 / gui.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  5KB  |  213 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Yannick Koehler
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/intuitionbase.h>
  11. #include <intuition/classes.h>
  12. #include <intuition/classusr.h>
  13. #include <intuition/imageclass.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <libraries/gadtools.h>
  16. #include <graphics/displayinfo.h>
  17. #include <graphics/gfxbase.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/intuition_protos.h>
  20. #include <clib/gadtools_protos.h>
  21. #include <clib/graphics_protos.h>
  22. #include <clib/utility_protos.h>
  23. #include <string.h>
  24. #include <clib/diskfont_protos.h>
  25.  
  26. #include <pragmas/exec_pragmas.h>
  27. #include <pragmas/intuition_pragmas.h>
  28. #include <pragmas/gadtools_pragmas.h>
  29. #include <pragmas/graphics_pragmas.h>
  30. #include <pragmas/utility_pragmas.h>
  31.  
  32. #include "gui.h"
  33.  
  34. struct Screen             *Scr = NULL;
  35. UBYTE                      *PubScreenName = NULL;
  36. APTR                        VisualInfo = NULL;
  37. struct Window             *SMWnd = NULL;
  38. struct Gadget              *SMGList = NULL;
  39. struct Gadget             *SMGadgets[2];
  40. UWORD                       SMWidth = 372;
  41. UWORD                       SMHeight = 87;
  42. UBYTE                      *SMWdt = "ScreenMenu V1.2 by Yannick Koehler";
  43. struct TextAttr         *Font, Attr;
  44. UWORD                       FontX, FontY;
  45. UWORD                      OffX, OffY;
  46. struct TextFont            *SMFont = NULL;
  47.  
  48. UBYTE *Gadget100Labels[] = {
  49.     (UBYTE *)"Normal Screen Name",
  50.     (UBYTE *)"Public Screen Name",
  51.     /*(UBYTE *)"EGS Screen Name",*/
  52.     NULL 
  53. };
  54.  
  55. UWORD SMGTypes[] = {
  56.     LISTVIEW_KIND,
  57.     CYCLE_KIND
  58. };
  59.  
  60. struct NewGadget SMNGad[] = {
  61.     5, 16, 362, 72, NULL, NULL, GD_Gadget00, 0, NULL, (APTR)1L,
  62.     5, 3, 362, 13, NULL, NULL, GD_Gadget10, 0, NULL, (APTR)2L
  63. };
  64.  
  65. ULONG SMGTags[] = {
  66.     (GTLV_ShowSelected), NULL, (GTLV_ScrollWidth), 17, (GTLV_Selected), 0, (TAG_DONE),
  67.     (GTCY_Labels), (ULONG)&Gadget100Labels[ 0 ], (TAG_DONE)
  68. };
  69.  
  70. static UWORD ComputeX( UWORD value )
  71. {
  72.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  73. }
  74.  
  75. static UWORD ComputeY( UWORD value )
  76. {
  77.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  78. }
  79.  
  80. static void ComputeFont( UWORD width, UWORD height )
  81. {
  82.     Forbid();
  83.     Font = &Attr;
  84.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  85.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  86.     FontX = GfxBase->DefaultFont->tf_XSize;
  87.     Permit();
  88.  
  89.     OffX = Scr->WBorLeft;
  90.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  91.  
  92.     if ( width && height ) {
  93.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  94.             goto UseTopaz;
  95.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  96.             goto UseTopaz;
  97.     }
  98.     return;
  99.  
  100. UseTopaz:
  101.     Font->ta_Name = (STRPTR)"topaz.font";
  102.     FontX = FontY = Font->ta_YSize = 8;
  103. }
  104.  
  105. int SetupScreen( void )
  106. {
  107.     ULONG num;
  108.  
  109.     num = LockIBase(0);
  110.     Scr = IntuitionBase->FirstScreen;
  111.     UnlockIBase(num);
  112.  
  113.     ComputeFont( 0, 0 );
  114.  
  115.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  116.         return( 2L );
  117.  
  118.     return( 0L );
  119. }
  120.  
  121. void CloseDownScreen( void )
  122. {
  123.     if ( VisualInfo ) {
  124.         FreeVisualInfo( VisualInfo );
  125.         VisualInfo = NULL;
  126.     }
  127.  
  128.     Scr = NULL;
  129. }
  130.  
  131. int OpenSMWindow( void )
  132. {
  133.     struct NewGadget     ng;
  134.     struct Gadget        *g;
  135.     UWORD                 lc, tc;
  136.     UWORD                 wleft = Scr->MouseX-4, wtop = Scr->MouseY-17, ww, wh;
  137.     UWORD                 rleft, rtop;
  138.  
  139.     ComputeFont( SMWidth, SMHeight );
  140.  
  141.     ww = ComputeX( SMWidth );
  142.     wh = ComputeY( SMHeight );
  143.  
  144.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  145.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  146.  
  147.     rleft = (((wleft - OffX) == 0) || ((wleft - OffX) > (Scr->Width-1 ))) ? 0 : wleft - OffX;
  148.     rtop  = (((wtop  - OffY) == 0) || ((wtop  - OffY) > (Scr->Height-1))) ? 0 : wtop - OffY;
  149.  
  150.     if ( ! ( SMFont = OpenDiskFont( Font )))
  151.         return( 5L );
  152.  
  153.     if ( ! ( g = CreateContext( &SMGList )))
  154.         return( 1L );
  155.  
  156.     for( lc = 0, tc = 0; lc < SM_CNT; lc++ ) {
  157.  
  158.         CopyMem((char * )&SMNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  159.  
  160.         ng.ng_VisualInfo = VisualInfo;
  161.         ng.ng_TextAttr   = Font;
  162.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  163.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  164.         ng.ng_Width      = ComputeX( ng.ng_Width );
  165.         ng.ng_Height     = ComputeY( ng.ng_Height);
  166.  
  167.         SMGadgets[ lc ] = g = CreateGadgetA((ULONG)SMGTypes[ lc ], g, &ng, ( struct TagItem * )&SMGTags[ tc ] );
  168.  
  169.         while( SMGTags[ tc ] ) tc += 2;
  170.         tc++;
  171.  
  172.         if ( NOT g )
  173.             return( 2L );
  174.     }
  175.  
  176.     if ( ! ( SMWnd = OpenWindowTags( NULL,
  177.                 WA_Left,    rleft,
  178.                 WA_Top,        rtop,
  179.                 WA_Width,    ww + OffX + Scr->WBorRight,
  180.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  181.                 WA_IDCMP,    LISTVIEWIDCMP|CYCLEIDCMP|IDCMP_INACTIVEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY,
  182.                 WA_Flags,     WFLG_NOCAREREFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_REPORTMOUSE,
  183.                 WA_Gadgets,    SMGList,
  184.                 WA_Title,   SMWdt,
  185.                 WA_CustomScreen,    Scr,
  186.                 WA_AutoAdjust,    TRUE,
  187.                 TAG_DONE )))
  188.     return( 4L );
  189.  
  190.     GT_RefreshWindow( SMWnd, NULL );
  191.  
  192.     return( 0L );
  193. }
  194.  
  195. void CloseSMWindow( void )
  196. {
  197.     if ( SMWnd        ) {
  198.         CloseWindow( SMWnd );
  199.         SMWnd = NULL;
  200.     }
  201.  
  202.     if ( SMGList      ) {
  203.         FreeGadgets( SMGList );
  204.         SMGList = NULL;
  205.     }
  206.  
  207.     if ( SMFont ) {
  208.         CloseFont( SMFont );
  209.         SMFont = NULL;
  210.     }
  211. }
  212.  
  213.